package com.dss.auto_deploy.rabbitmq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @ClassName: ConfirmCallBackHandler
 * @author: dongshoushan
 * @date: 2020年05月26日 16:15
 */
@Slf4j
@Service
public class ConfirmCallBackHandler implements RabbitTemplate.ConfirmCallback {
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        //根据回调的correlationDataId判断发送的哪条消息投递成功，哪条没有成功
        String correlationDataId = null;
        if (correlationData != null) {
            correlationDataId = correlationData.getId();
        }
        if (ack) {
            log.info("A-CONFIRM机制:消息投递成功:correlationId:{}", correlationDataId);
        } else {
            //TODO 消息投递失败,重新投递
            log.warn("A-CONFIRM机制:消息投递失败:correlationId:{},cause:{}", correlationDataId, cause);
        }
    }
}
